#include "haptic_interface.h"
#include "sih6887_reg.h"
#include <stdint.h>
#include "peripheral_i2c.h"

haptic_reg_config_t sih6887_default_list = {
	.reg_num = 119,
	.reg_cont = {
		{0x34, 0x23}, //波形采样率24k
		{0x42, 0x05},
		{0x43, 0x4C}, //vboost 8.5v
		{0x68, 0x48},
		{0x80, 0xE0},
		{0x81, 0x01},
		{0x82, 0x24},
		{0x83, 0x8B},
		{0x84, 0x36},
		{0x85, 0x05},
		{0x86, 0x50},
		{0x87, 0x23},
		{0x88, 0x00},
		{0x89, 0x04},
		{0x8A, 0x32},
		{0x8B, 0x00},
		{0x8C, 0xF0},
		{0x8D, 0x01},
		{0x8E, 0x00},
		{0x8F, 0xA0},
		{0x90, 0x0F},
		{0x91, 0x00},
		{0x92, 0x95},
		{0x93, 0x0B},
		{0x94, 0x00},
		{0x95, 0x9A},
		{0x96, 0x78},
		{0x97, 0x01},
		{0x98, 0x33},
		{0x99, 0x0B},
		{0x9A, 0x00},
		{0x9B, 0xCC},
		{0x9C, 0x04},
		{0x9D, 0x00},
		{0x9E, 0x99},
		{0x9F, 0x01},
		{0xA0, 0x00},
		{0xA1, 0x65},
		{0xA2, 0x73},
		{0xA3, 0xFE},
		{0xA4, 0x76},
		{0xA5, 0x10},
		{0xA6, 0x02},
		{0xA7, 0x71},
		{0xA8, 0x1C},
		{0xA9, 0x00},
		{0xAA, 0x15},
		{0xAB, 0xC4},
		{0xAC, 0x0C},
		{0xAD, 0xBC},
		{0xAE, 0x0A},
		{0xAF, 0x00},
		{0xB0, 0x03},
		{0xB1, 0x01},
		{0xB2, 0x00},
		{0xB3, 0x50},
		{0xB4, 0x0B},
		{0xB5, 0x00},
		{0xB6, 0x67},
		{0xB7, 0x15},
		{0xB8, 0x00},
		{0xB9, 0x80},
		{0xBA, 0xCC},
		{0xBB, 0x04},
		{0xBC, 0x00},
		{0xBD, 0xCC},
		{0xBE, 0x04},
		{0xBF, 0x00},
		{0xC0, 0x02},
		{0xC2, 0x04},
		{0xC3, 0x00},
		{0xC4, 0x10},
		{0xC5, 0x00},
		{0xC8, 0x14},
		{0xC9, 0x00},
		{0xCA, 0x00},
		{0xCB, 0x24},
		{0xCC, 0x1A},
		{0xCD, 0x06},
		{0xCE, 0x1A},
		{0xCF, 0x1A},
		{0xD0, 0x06},
		{0xD1, 0x1A},
		{0xD2, 0x1A},
		{0xD3, 0x06},
		{0xD4, 0x1A},
		{0xD5, 0x01},
		{0xD6, 0x09},
		{0xD7, 0x09},
		{0xD8, 0x01},
		{0xD9, 0x07},
		{0xE0, 0x36},
		{0xE1, 0x01},
		{0xE2, 0x00},
		{0xE3, 0x80},
		{0xE4, 0x00},
		{0xE5, 0x10},
		{0xE6, 0x00},
		{0xE7, 0xD8},
		{0xE8, 0xD4},
		{0xE9, 0xFF},
		{0xEA, 0xF8},
		{0xEB, 0x1A},
		{0xEC, 0x00},
		{0xED, 0x01},
		{0xEE, 0x16},
		{0xEF, 0x00},
		{0xF0, 0xE2},
		{0xF1, 0x02},
		{0xF2, 0x00},
		{0xF3, 0x46},
		{0xF4, 0x20},
		{0xF5, 0x00},
		{0xF6, 0x0C},
		{0xF7, 0xFE},
		{0xF8, 0xFF},
		{0xF9, 0x00},
		{0xFA, 0x08},
		{0xFB, 0x00},
	}
};
haptic_reg_config_t sih6887_tracking_list = {
	.reg_num = 21,
	.reg_cont = {
		{0x83, 0x8B},
		{0x84, 0x36},
		{0x86, 0x50},
		{0x87, 0x23},
		{0x88, 0x00},
		{0x89, 0x04},
		{0x8A, 0x32},
		{0x8B, 0x00},
		{0xCB, 0x24},
		{0xCC, 0x1A},
		{0xCD, 0x06},
		{0xCE, 0x1A},
		{0xCF, 0x1A},
		{0xD0, 0x06},
		{0xD1, 0x1A},
		{0xD2, 0x1A},
		{0xD3, 0x06},
		{0xD4, 0x1A},
		{0xC3, 0xCD},
		{0xC4, 0x04},
		{0xC5, 0x00},
	}
};
/* ram data */
const uint8_t sih6887_ram_test_data[] = {
0x2C, 0x8C, 0x08, 0x00,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xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCC, 0xCE, 0xD0, 0xD2, 0xD5, 0xD7, 0xDA, 
0xDD, 0xE0, 0xE3, 0xE7, 0xEA, 0xEE, 0xF1, 0xF5, 0xF8, 0xFC, 0x00, 0x04, 0x07, 0x0B, 0x0E, 0x12, 
0x15, 0x19, 0x1C, 0x1F, 0x22, 0x25, 0x28, 0x2B, 0x2D, 0x30, 0x32, 0x34, 0x36, 0x37, 0x39, 0x3A, 
0x3B, 0x3B, 0x3C, 0x3C, 0x3C, 0x3C, 0x3B, 0x3B, 0x3A, 0x39, 0x37, 0x36, 0x34, 0x32, 0x30, 0x2E, 
0x2B, 0x29, 0x26, 0x23, 0x20, 0x1D, 0x19, 0x16, 0x12, 0x0F, 0x0B, 0x08, 0x04
};
const uint8_t sih6887_ram_test_data_0[] = {
//0xF1, 0x38, 0x08, 0x00, 0x01, 0x08, 0x11, 0x09, 0x42, 0x09, 0x43, 0x0A, 0x74, 0x0A, 0x75, 0x0B, 
//0xA6, 0x0B, 0xA7, 0x0E, 0x0A, 0x00, 0x04, 0x09, 0x0D, 0x11, 0x15, 0x19, 0x1D, 0x21, 0x25, 0x28, 
//0x2C, 0x2F, 0x32, 0x35, 0x38, 0x3A, 0x3D, 0x3F, 0x40, 0x42, 0x43, 0x44, 0x45, 0x46, 0x46, 0x46, 
//0x46, 0x45, 0x44, 0x43, 0x42, 0x40, 0x3F, 0x3D, 0x3A, 0x38, 0x35, 0x32, 0x2F, 0x2C, 0x29, 0x25, 
//0x21, 0x1D, 0x19, 0x15, 0x11, 0x0D, 0x09, 0x04, 0x00, 0xFC, 0xF8, 0xF3, 0xEF, 0xEB, 0xE7, 0xE3, 
//0xDF, 0xDB, 0xD8, 0xD4, 0xD1, 0xCE, 0xCB, 0xC8, 0xC6, 0xC3, 0xC1, 0xC0, 0xBE, 0xBD, 0xBC, 0xBB, 
//0xBA, 0xBA, 0xBA, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0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1, 0xE9, 0xE1, 0xDA, 0xD2, 0xCB, 0xC4, 0xBD, 0xB7, 0xB1, 0xAB, 0xA5, 
0xA0, 0x9B, 0x96, 0x92, 0x8E, 0x8B, 0x88, 0x86, 0x84, 0x83, 0x82, 0x81, 0x81, 0x82, 0x82, 0x84, 
0x86, 0x88, 0x8B, 0x8E, 0x92, 0x96, 0x9A, 0x9F, 0xA5, 0xAA, 0xB0, 0xB6, 0xBD, 0xC4, 0xCB, 0xD2, 
0xD9, 0xE1, 0xE8, 0xF0, 0xF8,
};

int haptic2_init(){
	int ret;
	GPIO4->DO_f.P4 = 0;
	haptic_msleep(10);
	GPIO4->DO_f.P4 = 1;
	if(0 == sih6887_check_chipid(sih6887_read_chipid())){
		ret  = sih6887_init();
		if(ret){
			hp_err("sih6887 init failed !");
			return -1;
		}
		sih6887_HapticCalib();//上电需要校准，只需要校准一次
		//1号波形短振一次
		MotorParam testparam = {.type = SIH_RAM_MODE,.waveParam = {.wave=1,.loop=0},};
		sih6887_SetParam(&testparam);
		sih6887_HapticStart(1);//开始振动
	}
}

static int haptic_i2c_update_bits(uint8_t reg_addr, uint8_t mask, uint8_t reg_data)
{
	int ret = -1;
	//TODO
	//调用系统的i2c更新bit位函数
	//example : ret = i2c_update_bits(reg,mask,val);
	//return ret;
		uint8_t reg_val = 0;
	haptic_msleep(1);
	IIC_mem_read_bytes(reg_addr, &reg_val, 1);
	printf("read %hhX : %hhX, %hhX, %hhX\n", reg_addr, reg_val, mask, reg_data);
	reg_val &= ~mask;
	reg_val |= (reg_data & mask);
	haptic_msleep(1);
	printf("write %hhX to %hhX\n", reg_val, reg_addr);
	IIC_mem_write_bytes(reg_addr, &reg_val, 1);
	haptic_msleep(1);
	return 0;
}

int32_t haptic_msleep(uint32_t ms)
{
	//TODO
	//调用系统休眠函数
		volatile uint16_t d;
	while(ms --){
		d = 512*8;
		while(d--);
	}
	return 0;
}


static void sih6887_ram_init_ctrl(uint8_t flag)
{
	if (flag)
		haptic_i2c_update_bits(SIH688X_REG_SYSCTRL1, SIH_SYSCTRL1_BIT_ENRAMINIT_MASK, SIH_SYSCTRL1_BIT_RAMINIT_EN);
	else
		haptic_i2c_update_bits(SIH688X_REG_SYSCTRL1, SIH_SYSCTRL1_BIT_ENRAMINIT_MASK, SIH_SYSCTRL1_BIT_RAMINIT_OFF);
}


static uint8_t sih6887_if_chip_is_done()
{
	uint8_t flag = 0;
	uint8_t reg_val = 0;

	haptic_i2c_read(SIH688X_REG_SYSINT, SIH_I2C_OPERA_BYTE_ONE, &reg_val);
	flag = (reg_val & SIH_SYSINT_BIT_DONE) == SIH_SYSINT_BIT_DONE;

	return flag;
}

static uint8_t sih6887_if_chip_is_standby()
{
	uint8_t flag = 0;
	uint8_t reg_val = 0;

	haptic_i2c_read(SIH688X_REG_SYSSST, SIH_I2C_OPERA_BYTE_ONE, &reg_val);
	flag = (reg_val & SIH_SYSSST_BIT_STANDBY) == SIH_SYSSST_BIT_STANDBY;

	return flag;
}


static void sih6887_set_ram_go(uint8_t flag)
{
	if (flag)
		haptic_i2c_update_bits(SIH688X_REG_GO, SIH_GO_BIT_RAM_GO_MASK, SIH_GO_BIT_RAM_GO_ENABLE);
	else
		haptic_i2c_update_bits(SIH688X_REG_GO, SIH_GO_BIT_RAM_GO_MASK, SIH_GO_BIT_RAM_GO_DISABLE);
}
static void sih6887_set_brk_state(uint8_t flag)
{
	if (flag)
		haptic_i2c_update_bits(SIH688X_REG_MAIN_STATE_CTRL, SIH_MODECTRL_BIT_RAM_BRK_MASK, SIH_MODECTRL_BIT_RAM_BRK_EN);
	else
		haptic_i2c_update_bits(SIH688X_REG_MAIN_STATE_CTRL, SIH_MODECTRL_BIT_RAM_BRK_MASK, SIH_MODECTRL_BIT_RAM_BRK_OFF);
}

static void sih6887_set_gain(uint8_t gain)
{
	hp_info("%s:set gain:0x%02x\n", __func__, gain);
	haptic_i2c_write(SIH688X_REG_PWM_PRE_GAIN, SIH_I2C_OPERA_BYTE_ONE, &gain);
}

static void sih6887_f0_tracking(uint8_t flag)
{
	if (flag)
		haptic_i2c_update_bits(SIH688X_REG_MAIN_STATE_CTRL, SIH_MODECTRL_BIT_TRACK_F0_MASK, SIH_MODECTRL_BIT_TRACK_F0_EN);
	else
		haptic_i2c_update_bits(SIH688X_REG_MAIN_STATE_CTRL, SIH_MODECTRL_BIT_TRACK_F0_MASK, SIH_MODECTRL_BIT_TRACK_F0_OFF);
}

static void sih6887_cont_go()
{
	haptic_i2c_update_bits(SIH688X_REG_GO, SIH_GO_BIT_F0_SEQ_GO_MASK, SIH_GO_BIT_F0_SEQ_GO_ENABLE);
}

static int32_t sih6887_f0_cali(uint32_t tracking_f0)
{
	int32_t tmp = 0;
	int32_t code = 0;

	if (tracking_f0 > sih6887_F0_VAL_MAX || tracking_f0 < sih6887_F0_VAL_MIN) {
		code = 0;
	} else {
		tmp = (int32_t)(tracking_f0 * sih6887_F0_CAL_COE
			/ sih6887_F0_VAL_STANDARD);
		code = (tmp - sih6887_F0_CAL_COE) / sih6887_F0_CALI_DELTA;
		/*
		* f0 calibration formulation:
		*
		* code = (tracking_f0 / target_f0 - 1) / 0.00288
		*
		* 0.00288 is calc coefficient
		*/
	}
	hp_info("%s:cali data:0x%02x\n", __func__, code);
	return code;
}

static void sih6887_upload_f0(uint8_t flag,uint32_t tracking_f0)
{
	uint8_t reg_val = 0;

	switch (flag) {
	case SIH_WRITE_ZERO:
		reg_val = 0;
		break;
	case SIH_F0_CALI_LRA:
		reg_val = sih6887_f0_cali(tracking_f0);
		break;
	default:
		hp_err("%s:err flag\n", __func__);
		break;
	}

	hp_info("%s:trim value:0x%02x\n", __func__, reg_val);

	haptic_i2c_write(SIH688X_REG_TRIM1,SIH_I2C_OPERA_BYTE_ONE, &reg_val);
}

static uint32_t sih6887_read_tracking_f0()
{
	uint8_t data[3] = {0};
	uint32_t tracking_f0_value;
	uint32_t ret=0;
	haptic_i2c_read(SIH688X_REG_T_HALF_TRACKING_0, SIH_I2C_OPERA_BYTE_THREE, data);
	tracking_f0_value = data[0] | data[1] << 8 | data[2] << 16;
	hp_info("data 0x%02x 0x%02x 0x%02x\n", data[0], data[1], data[2]);

	if(tracking_f0_value!=0)
		ret = sih6887_TRACKING_F0_COE / tracking_f0_value;

	hp_info("tracking_f0:%d\n",ret);
	return ret;
}

static void sih6887_set_wave_index(uint8_t wave)
{
	haptic_i2c_write(SIH688X_REG_WAVESEQ1, SIH_I2C_OPERA_BYTE_ONE, &wave);
}

static void sih6887_set_wave_loop(uint8_t loop)
{
	haptic_i2c_update_bits(SIH688X_REG_WAVELOOP1, WAVELOOP_SEQ_ODD_MASK, loop << 4);
}


int32_t sih6887_ShutDown()//马达下电
{
	int32_t ret = 0;

	//rst pin 脚拉低
	//gpio_set_value(sih_haptic->chip_attr.reset_gpio, SIH_RESET_GPIO_LOW);

	return ret;
}

int32_t sih6887_HapticStart()//开始振动
{
	int32_t ret = 0;
	hp_info("enter!\r\n");
	sih6887_set_ram_go(1);


	return ret;
}

int32_t sih6887_HapticStop()//停止振动
{
	int32_t ret = 0;
	uint32_t cnt = sih6887_WAIT_FOR_STANDBY_MAX_TRY;
	hp_info("enter!\r\n");
	/* stop chip */
	sih6887_set_ram_go(0);

	/* wait for auto brake over */
	while (cnt--) {
		if (!sih6887_if_chip_is_standby())
			hp_info("%s:wait for standby\n", __func__);
		else
			break;
		haptic_msleep(3);
	}

	return ret;
}

static void sih6887_set_boost_mode(uint8_t flag)
{
	hp_info("haptic boost mode %hhX\n",flag);
	if (flag) {
		haptic_i2c_update_bits(SIH688X_REG_SYSCTRL2, SIH_SYSCTRL2_BIT_BOOST_BYPASS_MASK,
			SIH_SYSCTRL2_BIT_BOOST_ENABLE);
	} else {
		haptic_i2c_update_bits(SIH688X_REG_SYSCTRL2, SIH_SYSCTRL2_BIT_BOOST_BYPASS_MASK,
			SIH_SYSCTRL2_BIT_BOOST_BYPASS);
	}
}


int32_t sih6887_SetParam(MotorParam *motorParam)//设置参数
{
	int32_t ret = 0;

	switch (motorParam->type) {
		case SIH_RAM_MODE:
			sih6887_set_boost_mode(1);
			sih6887_set_wave_index(motorParam->waveParam.wave);
			break;
		case SIH_RAM_LOOP_MODE:
			sih6887_set_boost_mode(0);
			sih6887_set_wave_index(motorParam->waveParam.wave);
			sih6887_set_wave_loop(motorParam->waveParam.loop);
			break;
		case SIH_SET_GAIN:
			if (motorParam->gain > 0x80)
			{
				motorParam->gain = 0x80;
			}
			sih6887_set_gain(motorParam->gain);
			break;
		case SIH_OTHER:
			hp_err("%s:wrong cmd!, type:%d\n", __func__, motorParam->type);
			break;
		default:
			break;
	}

	return ret;
}

static int32_t sih6887_ram_init()
{
	int32_t ret = 0;
	int32_t i;

	hp_info("enter\n");

	/* RAMINIT enable */
	sih6887_ram_init_ctrl(1);

	/* base addr */
	haptic_i2c_write(SIH688X_REG_BASE_ADDRH, SIH_I2C_OPERA_BYTE_ONE, &sih6887_ram_test_data[2]);
	haptic_i2c_write(SIH688X_REG_BASE_ADDRL, SIH_I2C_OPERA_BYTE_ONE, &sih6887_ram_test_data[3]);

	/* ram addr */
	haptic_i2c_write(SIH688X_REG_RAMADDRH, SIH_I2C_OPERA_BYTE_ONE, &sih6887_ram_test_data[2]);
	haptic_i2c_write(SIH688X_REG_RAMADDRL, SIH_I2C_OPERA_BYTE_ONE, &sih6887_ram_test_data[3]);

	/* write ram data */
	for (i = 4; i < sizeof(sih6887_ram_test_data); i++) {
		ret = haptic_i2c_write(SIH688X_REG_RAMDATA,SIH_I2C_OPERA_BYTE_ONE, &sih6887_ram_test_data[i]);
		if (ret < 0) {
			hp_err("i2c write failed !\n");
			break;
		}
	}

	/* RAMINIT disable */
	sih6887_ram_init_ctrl(0);
	hp_info("exit\n");
	return ret;
}

static int32_t sih6887_load_reg_list(haptic_reg_config_t *config)
{
	uint8_t reg_addr = 0;
	uint8_t reg_value = 0;
	int32_t i;
	int32_t ret = 0;

	for (i = 0; i < config->reg_num; i++) {
		reg_addr = config->reg_cont[i].reg_addr;
		reg_value = config->reg_cont[i].reg_value;
		ret = haptic_i2c_write(reg_addr, 1, &reg_value);
		if (ret < 0) {
			hp_err("i2c write failed !\n");
			break;
		}
		hp_info("%s:0x%02x:0x%02x\n", __func__, reg_addr, reg_value);
	}

	return ret;
}
static uint32_t sih6887_getTrackingF0()
{
	int32_t ret = 0;
	uint8_t cnt = sih6887_WAIT_FOR_STANDBY_MAX_TRY;
	uint32_t tracking_f0  = 0;

	ret = sih6887_HapticStop();

	/* load tracking f0 config */
	ret = sih6887_load_reg_list(&sih6887_tracking_list);

	/* init trim code */
	sih6887_upload_f0(SIH_WRITE_ZERO,0);

	/* tracking enable */
	sih6887_f0_tracking(0);

	/* play go */
	sih6887_cont_go();

	/* wait for standby */
	while (cnt--) {
		if (sih6887_if_chip_is_standby())
			break;
		haptic_msleep(3);
	}

	/* read f0 data */
	tracking_f0 = sih6887_read_tracking_f0();

	/* f0 calibration */
	sih6887_upload_f0(SIH_F0_CALI_LRA,tracking_f0);



	return tracking_f0;
}



int32_t sih6887_HapticCalib()//校准
{
	uint32_t ret = 0;
	uint32_t tracking_f0_value =SIH_F0_PRE_VALUE;
	uint32_t i=0;
	for (i = 0; i < SIH_F0_DETECT_TRY; i++) {
		tracking_f0_value = sih6887_getTrackingF0();
		if(tracking_f0_value<sih6887_F0_VAL_MAX && tracking_f0_value > sih6887_F0_VAL_MIN)
			break;
		haptic_msleep(200);
	}
	hp_info("tracking_f0_value = %d\n",tracking_f0_value);
	return ret;
}


int32_t sih6887_init()//初始化
{
	int32_t ret = 0;


	ret += sih6887_load_reg_list(&sih6887_default_list);

	ret += sih6887_ram_init();

	return ret;
}

int32_t sih6887_check_chipid(uint8_t chip_id)
{
    int32_t ret = 0;

    hp_info("chip id:0x%02x\r\n", chip_id);
    /* check chip id */
    if(chip_id != SIH688X_REG_CHIP_ID)
        ret = -1;

    return ret;
}

uint8_t sih6887_read_chipid(void)//读取芯片ID
{
	uint8_t chipId = 0x00;
	int32_t ret = 0;

	ret = haptic_i2c_read(SIH688X_REG_ID, SIH_I2C_OPERA_BYTE_ONE, &chipId);

	if (ret < 0)
		hp_err("read chip id failed!\n");

	return chipId;
}

void sih6887_dump_reg(void)
{
	int i ;
	uint8_t value;
	for(i=0;i<0xFD;i++){
		haptic_i2c_read(i,SIH_I2C_OPERA_BYTE_ONE,&value);
		hp_info("reg %02x:%02x\r\n",i,value);
	}
}

